package relu.R.weeds;
import relu.R.landscape.*;
import jfm.utils.*;
import java.io.*;

public final class testApp {
	public static void main(String[] args){

		int[] farmAreas=new int[]{250,250,250};
		String[] templateFiles=new String[] {"FP1_250.xml","FP2_250.xml","FP3_250.xml"};
		String[] mouFiles=new String[] {"mouFP1.xml","mouFP2.xml","mouFP3.xml"};

		String[] priceScenarios=new String[]{"2007","1","2","3","4","5","6","7","8","9","2008"};
		
		EnviroVsProfitDistribution sDist=new EnviroVsProfitDistribution();
		sDist.setCropPriceScenarios("Prices.csv");
//		ls.relaxLocations(1, 0.8);
//		ls.addFarm(244,"FP1.xml", "mouFP1.xml");
//		ls.addFarm(490,"FP2.xml", "mouFP2.xml");
//		ls.addFarm(3150,"FP3.xml", "mouFP3.xml");
		try{
		for(int pr=0;pr<2;pr++){
			sDist.setCropPricesForScenario(priceScenarios[pr]);
			for(int f=0;f<3;f++){ // Loop farm types 
				String fileName=(f+priceScenarios[pr]+"out.csv");
				FileWriter writer = new FileWriter(fileName);
				writer.append("startBirds,"+SpatialLandscape.oneLineCSVHeader()+"\n");
				for( int nBirds=1;nBirds<50;nBirds++){
					int actualBirds=nBirds*50;
					SpatialLandscape ls=new SpatialLandscape();	
					ls.applySocioEconomicDistribution(sDist);
					ls.generateFarmSpatialDistribution(new double[]{250}, 1);
					ls.addFarm(farmAreas[f], templateFiles[f], mouFiles[f]);
					ls.createAndDistributeFields(5000);
					IFSSorter ifs=new IFSSorter();
					ifs.initFromCSV("IFSWeeds.csv");
					ls.createWeedPopulations(ifs);
					ls.solveFarmLPs();
					ls.equilibrateWeedPopulations(100);
					ls.stepSummer(actualBirds);
					ls.stepWinter();
					writer.append(actualBirds+","+ls.oneLineCSVSummary(0)+"\n");
					writer.flush();
				}
				writer.close();
			}
		}} catch (Exception ex){
			throw new Error(ex.getMessage());
		}

		
	}
}
